<!--
* description: 采购供应商确认-发货
-->
<template>
  <section class="detail">
    <el-dialog
      v-dialogDrag
      :close-on-click-modal="false"
      title="驳回原因"
      :append-to-body="true"
      :visible.sync="showDialog"
      width="500px"
      @close="close"
    >
      <dialogHeader slot="title" title="驳回原因" :styleType="$store.state.app.dialogType"></dialogHeader>
      <div class="filter-container filter-params">
        <el-row :gutter="26">
          <component
            v-for="comp in tableComponents.filter(o => o.isMust === true)"
            :ref="comp.isRequire ? comp.isRequire+ comp.compKey : comp.compKey"
            :validrule="comp.validrule"
            :key="comp.compKey"
            :codeField="comp.codeField"
            :textField="comp.textField"
            :popupsKey="comp.compKey"
            :is="comp.component"
            :code="formField[comp.codeField]"
            :text="formField[comp.textField]"
            @changeCode="getComponentCode"
            @focusCode="getFocusCode"
            :disabled="comp.disabled"
            :isRequire="comp.isRequire"
            :span="comp.span || 8"
            :isMul="comp.isMul"
            :labelName="comp.labelName"
            :lookuptype="comp.lookuptype"
            :dateOptionsType="comp.dateOptionsType"
          ></component>
        </el-row>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button
          v-for="comp in tableButtons"
          :key="comp.compKey"
          :type="comp.type"
          @click="comp.clickEvent"
        >{{comp.text}}</el-button>
      </div>
    </el-dialog>
  </section>
</template>
<script>
import { formMixins } from "@/components/wms/mixins/formMixins";
import request from "@/utils/request";
export default {
  // 组件混入对象
  mixins: [formMixins],
  components: {
    dialogHeader: () => import("@/components/dialogHeader") //弹窗标题
  },
  props: {
    isRejectShow: { type: Boolean, default: false },
    checkTableList: { type: Array, default: [] }
  },
  data() {
    return {
      // 是否显示
      showDialog: this.isRejectShow,
      // 动态组件-按钮
      tableButtons: [
        {
          compKey: "btnKey1",
          type: "primary",
          size: "small",
          clickEvent: () => this.save(),
          text: "保存" //"保存"
        },
        {
          compKey: "btnKey2",
          type: "",
          size: "small",
          clickEvent: () => this.reset(),
          text: "重置" //"重置"
        }
      ],
      // 动态组件-查询条件
      tableComponents: [
        {
          compKey: "edit_compKey1",
          labelName: "驳回原因",
          span: 24,
          codeField: "MESSAGE",
          component: () => import("@/components/wms/textareaInput"),
          isMust: true,
          isRequire: true
        }
      ],
      // 表单数据（无需赋值，由混入对象赋值）
      formField: {
        MESSAGE: ""
      }
    };
  },
  methods: {
    save() {
      if(this.formField.MESSAGE==""){
            this.$message({
          message: "请输入驳回原因"
        });
        return;
      }
      let detailLoading = this.$loading({
        lock: true,
        text: "正在保存...",
        background: "rgba(0, 0, 0, 0.7)",
        fullscreen: true
      });
      request({
        url: "/mp/wm/vl/warehouse/materialsStyle/auditMaterials.do",
        method: "post",
        data: {
          STATE: "03",
          IDS: this.checkTableList,
          MESSAGE: this.formField.MESSAGE
        }
      })
        .then(res => {
          detailLoading.close();
          if (res.result === "1") {
            this.showDialog = false;
            this.$emit("rejectSuccess");
            this.$message({
              message: "保存成功",
              type: "success"
            });
          } else {
            this.$message({
              message: res.debugMsg ? res.debugMsg : res.msg,
              type: "warn"
            });
          }
        })
        .catch(err => {
          this.detailLoading.close();
          console.info(err);
        });
    },
    close() {
      this.showDialog = false;
      this.$emit("rejectClose");
    }
  }
};
</script>
<style type="text/css" lang="scss" scoped>
.dialogTitle {
  text-align: left;
  overflow: hidden;
}
.dialogTitleButton {
  float: right;
}
</style>